local skel = fk.CreateSkill{
  name = "lb__shihu",
  tags = {Skill.Compulsory}
}

Fk:loadTranslationTable{
  ["lb__shihu"] = "誓护",
  --[":lb__shihu"] = "<b>锁定技</b>，当你造成或受到伤害后，你摸体力值数张牌，若你的手牌数为全场最大，你将此技能的“摸”改为“弃”并使用一张牌，否则你复原所有技能，替换武将为“<b>克拉拉</b>”。当你死亡时，替换武将为“<b>克拉拉</b>”。",

  --[":lb__shihu"] = "<b>锁定技</b>，当你造成或受到伤害后，你摸体力值数张牌，然后若你的手牌数为全场最大，你弃置体力值数张牌并使用一张牌，否则你复原所有技能，替换武将为“<b>克拉拉</b>”。当你死亡时，替换武将为“<b>克拉拉</b>”。",
  --9.7
  --[":lb__shihu"] = "<b>锁定技</b>，当你不因此造成或受到伤害后，你摸体力值数张牌并使用一张牌，然后若你的手牌数为全场最大，你弃置体力值数张牌，否则你复原所有技能，替换武将为“<b>克拉拉</b>”。",
  --9.8
  [":lb__shihu"] = "<b>誓护</b>：<b>锁定技</b>，每回合限一次，当你造成或受到伤害后，你摸体力值数张牌并使用一张牌，然后若你的手牌数为全场最大，你弃置体力值数张牌，否则你复原所有技能，替换武将为“<a href='#lb__shihu_kelala'><font color='red'>克拉拉</font></a>”。",


  ["#lb__shihu_kelala"] = "<b>克拉拉</b> 3/3 <br>" ..
  "<b>冀明</b>：<b>限定技</b>，出牌阶段，你可以重铸一张牌并令所有其他角色也如此做，然后你使用因此重铸的一张牌。<br>"..
  "<b>影翅</b>：<b>锁定技</b>，当你造成或受到伤害时，你重铸X张牌（不足则全重铸），若你的体力值不大于X (X为此技能发动次数）且"..
  "“<a href='#lb__yingchi_shiwaluo'><font color='red'>史瓦罗</font></a>”存活，"..
  "你替换武将为 “<a href='#lb__yingchi_shiwaluo'><font color='red'>史瓦罗</font></a>”，"..
  "你与“<a href='#lb__yingchi_shiwaluo'><font color='red'>史瓦罗</font></a>”的体力与体力上限独立计算。",

  ["#lb__shihu_dis"] = "誓护：请弃置 %arg 张牌",
  ["#lb__shihu_use"] = "誓护：请使用一张牌",
  --["@@lb__shihu"] = "誓护 弃牌",

  ["$lb__shihu1"] = "离开克拉拉。",
  ["$lb__shihu2"] = "躲起来。",
}

local shihu_spec = {
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    --[[ 9.7
    if player:hasSkill(skel.name) and target == player then
      local room = player.room --- @type Room
      local use = room.logic:getCurrentEvent():findParent(GameEvent.UseCard)
      return not use or 
      not use.data.extra_data or
      not use.data.extra_data.lb__shihu or
      not use.data.extra_data.lb__shihu == player
    end
    --]]
    return player:hasSkill(skel.name) and target == player and player:usedSkillTimes(skel.name) == 0
  end,
  ---@param player ServerPlayer
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(player.hp, skel.name)
    --[[
    if player:getMark("@@lb__shihu") == 0 then
      player:drawCards(player.hp, skel.name)
    else
      room:askToDiscard(player, {
        min_num = player.hp,
        max_num = player.hp,
        include_equip = true,
        cancelable = false,
        prompt = "#lb__shihu_dis:::"..player.hp,
        skill_name = skel.name,
      })
    end
    --]]
    local use = room:askToUseRealCard(player, {
      pattern = ".",
      skill_name = skel.name,
      cancelable = false,
      prompt = "#lb__shihu_use",
      skip = true,
    })
    if use then
      --use.extra_data = use.extra_data or {}
      --use.extra_data.lb__shihu = player
      room:useCard(use)
    end
    if table.find(room.alive_players,function (to)
      return to:getHandcardNum() > player:getHandcardNum()
    end) then
      --room:setPlayerMark(player, "@@lb__shihu", 0)
      for skill_name, scope in pairs(player.skillUsedHistory) do
        if Fk.skills[skill_name] and Fk.skills[skill_name]:isPlayerSkill() then
          player:setSkillUseHistory(skill_name)
        end
      end
      local list = room:getTag("lb__shihu"..player.id) or {lb__kelala = {3, 3}}
      if list.lb__kelala[1] > 0 and list.lb__kelala[2] > 0 then
        list.lb__shiwaluo = {player.hp, player.maxHp}
        room:setTag("lb__shihu"..player.id, list)
        room:changeHero(player, "lb__kelala", false, player.deputyGeneral == "lb__shiwaluo", true, false)
        player.hp = list.lb__kelala[1]
        player.maxHp = list.lb__kelala[2]
        room:broadcastProperty(player, "maxHp")
        room:broadcastProperty(player, "hp")
        --p(room:getTag("lb__shihu"..player.id))
      end
    else
      --room:setPlayerMark(player, "@@lb__shihu", 1)
      room:askToDiscard(player, {
        min_num = player.hp,
        max_num = player.hp,
        include_equip = true,
        cancelable = false,
        prompt = "#lb__shihu_dis:::"..player.hp,
        skill_name = skel.name,
      })
    end
  end,
}

skel:addEffect(fk.Damage, shihu_spec)
skel:addEffect(fk.Damaged, shihu_spec)

--[[
skel:addEffect(fk.BeforeGameOverJudge, {
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(skel.name, false, true) and target == player
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list = room:getTag("lb__shihu"..player.id) or {lb__kelala = {3, 3}}
    if list.lb__kelala[1] > 0 and list.lb__kelala[2] > 0 then
      list.lb__shiwaluo = {player.hp, player.maxHp}
      room:setTag("lb__shihu"..player.id, list)
      room:setPlayerProperty(player, "dead", false)
      player._splayer:setDied(false)
      room:setPlayerProperty(player, "dying", false)
      table.insertIfNeed(room.alive_players, player)
      room.logic:getCurrentEvent().parent:shutdown()
      room:changeHero(player, "lb__kelala", false, player.deputyGeneral == "lb__shiwaluo", true, false)
      player.hp = list.lb__kelala[1]
      player.maxHp = list.lb__kelala[2]
      room:broadcastProperty(player, "maxHp")
      room:broadcastProperty(player, "hp")
    end
  end,
})
--]]
return skel